local zhuanzhan = fk.CreateSkill {
  name = "lingling__zhuanzhan",
  tags = { Skill.Compulsory },
  dynamic_desc = function (self, player, lang)
    if player:getMark(self.name) > 0 then
      return "lingling__zhuanzhan_inner"
    end
  end,
}

Fk:loadTranslationTable{
  ["lingling__zhuanzhan"] = "转战",
  [":lingling__zhuanzhan"] = "锁定技，你使用【杀】的次数上限+1。当你每回合第二次造成/受到伤害时，你摸三张牌/弃置一张牌防止之。",

  [":lingling__zhuanzhan_inner"] = "锁定技，你使用【杀】的次数上限+1。当你每回合第二次造成/受到伤害时，你摸三张牌/弃置一张牌。",
}

zhuanzhan:addEffect(fk.DamageCaused, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(zhuanzhan.name) and
      #player.room.logic:getActualDamageEvents(2, function (e)
        return e.data.from == player
      end, Player.HistoryTurn) == 1 and
      player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function (self, event, target, player, data)
    if player:getMark(zhuanzhan.name) == 0 then
      data:preventDamage()
    end
    player:drawCards(3, zhuanzhan.name)
  end,
})

zhuanzhan:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(zhuanzhan.name) and
      #player.room.logic:getActualDamageEvents(2, function (e)
        return e.data.to == player
      end, Player.HistoryTurn) == 1 and
      player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function (self, event, target, player, data)
    if player:getMark(zhuanzhan.name) == 0 then
      data:preventDamage()
    end
    player.room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = zhuanzhan.name,
      cancelable = false,
    })
  end,
})

zhuanzhan:addEffect("targetmod", {
  residue_func = function (self, player, skill, scope, card, to)
    if player:hasSkill(zhuanzhan.name) and scope == Player.HistoryPhase and card.trueName == "slash" then
      return 1
    end
  end,
})

return zhuanzhan
